package per.wsj.okhttp;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import java.util.Arrays;
import java.util.HashMap;

//import per.wsj.test.simple.CallBackUtil;
//import per.wsj.test.simple.UrlHttpUtil;

public class Main2Activity extends Activity {

    @RequiresApi(api = Build.VERSION_CODES.N_MR1)
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btn = findViewById(R.id.btnRequest1);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Main2Activity.this,"",Toast.LENGTH_LONG).show();
            }
        });

//        public static final MediaType JSON
//                = MediaType.get("application/json; charset=utf-8");
//
//        OkHttpClient client = new OkHttpClient();
//
//        String post(String url, String json) throws IOException {
//            RequestBody body = RequestBody.create(json, JSON);
//            Request request = new Request.Builder()
//                    .url(url)
//                    .post(body)
//                    .build();
//            try (Response response = client.newCall(request).execute()) {
//                return response.body().string();
//            }
//        }

        /*ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

        ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "id1")
                .setShortLabel("Web site")
                .setLongLabel("Open the web site")
                .setIcon(Icon.createWithResource(this, R.drawable.ic_load_empty))
                .setIntent(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("https://www.mysite.example.com/")))
                .build();

        shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));*/
    }

//    private void postData() {
//        String url = "https://www.baidu.com/";
//        HashMap<String, String> paramsMap = new HashMap<>();
//        paramsMap.put("title","title");
//        paramsMap.put("desc","desc");
//        UrlHttpUtil.post(url, paramsMap, new CallBackUtil.CallBackString() {
//            @Override
//            public void onFailure(int code, String errorMessage) {
//
//            }
//
//            @Override
//            public void onResponse(String response) {
//                Toast.makeText(Main2Activity.this,"Success",Toast.LENGTH_SHORT).show();
//                Log.d("kwwl",response);
//            }
//        });
//    }
//
//    private void getData() {
//        String url = "https://www.baidu.com/";
//        UrlHttpUtil.get(url, new CallBackUtil.CallBackString() {
//            @Override
//            public void onFailure(int code, String errorMessage) {
//
//            }
//
//            @Override
//            public void onResponse(String response) {
//                Toast.makeText(Main2Activity.this,"Success",Toast.LENGTH_SHORT).show();
//                Log.d("kwwl",response);
//            }
//        });
//    }
}
